package com.cykj.pos.mapper;

import com.cykj.pos.domain.BizMerchTransactions;
import com.cykj.pos.domain.BizTransactionAmountEntity;
import com.cykj.pos.domain.SynchronizationDataDTO;
import com.cykj.pos.domain.dto.BizPosMessage;
import com.cykj.pos.domain.vo.BizMerchParentRelated;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface BizTransactionAmountMapper {
    /**
     * 存储交易通知
     * @param synchronizationDataDTO
     * @return
     */
    void insertBizTransactionAmount(SynchronizationDataDTO synchronizationDataDTO);

    void insertBizTransactionAmountHistory(SynchronizationDataDTO synchronizationDataDTO);

    /**
     * xxl储存偷单的交易通知
     * @param synchronizationDataDTO
     */
    void insertBizTransactions(SynchronizationDataDTO synchronizationDataDTO);

    /**
     * 更改pos1.0交易通知  可见
     * @return
     */
    int updateBizTransactionAmount(BizMerchTransactions bizMerchTransactions);

    /**
     * 更改交易记录表变为不偷单
     * @param bizMerchTransactions
     * @return
     */
    int updateBizMerchTransactions(BizMerchTransactions bizMerchTransactions);

    /**
     * 查询pos1.0
     * @param bizMerchTransactions
     * @return
     */
    BizPosMessage selectPos(BizMerchTransactions bizMerchTransactions);

    List<BizPosMessage> selectPosSy();

    /**
     * 更新手续费
     * @param syDTO
     * @return
     */
    int updateBizTransactionAmountAddiAmount(BizPosMessage syDTO);

    /**
     * 插入拿账分账记录表
     * @param syDTO
     * @return
     */
    int insertBizRateMoney(BizPosMessage syDTO);

    @Select(" select pos_sn from biz_transaction_amount")
    List<String> selectAllPos();

    @Select("select parent_id,child_id from biz_merch_parent_related where child_id = (SELECT merch_id from biz_pos_machine where pos_code = #{posCode}) and node = 1")
    BizMerchParentRelated selectParenId(String posCode);
    @Update("update biz_transaction_amount set merch_id = #{childId},parent_id = #{parentId} where pos_sn = #{posCode}")
    void updateBizTransactionAmountMerchIdAndParentId(BizMerchParentRelated bizMerchParentRelated);

    @Select("select * from biz_transaction_amount where uuid = #{uuid}")
    SynchronizationDataDTO selectOne(String uuid);

    @Update("update biz_transaction_amount set tran_sim = #{tran_sim} , sim_amt = #{sim_amt} where uuid = #{uuid}")
    void updateBizTransactionAmountPos(SynchronizationDataDTO synchronizationDataDTO);

    int updateBizTransactionAmountSuffix(BizMerchTransactions bizMerchTransactions);

    String selectSuffix(BizMerchTransactions bizMerchTransactions);

    @Select("select * from  biz_transaction_amount where id not in (  select id from biz_transaction_amount t where host_date >'2022-11-18 16:00:00' and host_date<'2022-11-19 12:00:00' and  t.uuid in (select transaction_amount_id from biz_profit_deatail where  create_time >'2022-11-18 16:00:00' and create_time<'2022-11-19 12:00:00'\n" +
            ") ) and host_date >'2022-11-18 16:00:00' and host_date<'2022-11-19 12:00:00' and merch_id>=690 order by merch_id")
    List<BizTransactionAmountEntity> selectAllAmount();

    @Select("select d.dept_id from biz_pos_machine m left join biz_merchant bm on m.merch_id=bm.merch_id left join sys_user u on bm.user_id=u.user_id left join sys_dept d on u.dept_id=d.dept_id where m.pos_code=#{pos_sn}")
    Long selectDeptIdByPosCode(String pos_sn);
    @Select("select bme.create_time from biz_merchant_entry bme  where bme.merchant_no=#{merchant_no}")
    String getregisterTime(String merchant_no);
    @Insert("insert into wffllf (pos_sn,merchant_no,uuid,type) value (#{pos_sn},#{merchant_no},#{uuid},#{type})")
    void insertCZRZ(@Param("pos_sn") String pos_sn, @Param("merchant_no") String merchant_no, @Param("uuid") String uuid, @Param("type")int type);

    @Select("select count(1) from biz_noback where sn=#{posSn}")
    int selectBackBySn(String posSn);
}
